package com.high.school.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.high.school.model.User;
import com.high.school.service.UserService;

@Controller
public class UserController {
	
	@Autowired
	UserService userService;
	
	@RequestMapping("result")
    public String listUsers(Map<String, Object> map) {
 
        map.put("user", new User());
        map.put("userList", userService.listUser());
 
        return "user";
    }
	
	@RequestMapping(value = "result", method = RequestMethod.POST)
    public String addUser(@ModelAttribute("user")
    User user, BindingResult result) {

       userService.addUser(user);
 
       return "redirect:/result";
    }
	
	

}
